package team.star.werespos.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import team.star.werespos.model.entity.OrderDetail;

import java.util.List;
import java.util.Map;

/**
 * OrderDetailMapper interface<br/>
 *
 * @author hdonghong
 * @since 2019/05/04
 */
public interface OrderDetailMapper extends BaseMapper<OrderDetail> {

    @Select("select SUM(food_quantity) quantity, DATE_FORMAT(create_time,'%Y-%m-%d') days from order_detail GROUP BY days HAVING days LIKE CONCAT(#{year}, '%') order by days DESC LIMIT 10")
    List<Map> getQuantityByDay(@Param("year") int year);

    @Select("select SUM(food_quantity) quantity, DATE_FORMAT(create_time,'%Y-%u') weeks from order_detail GROUP BY weeks HAVING weeks LIKE CONCAT(#{year}, '%') order by weeks DESC LIMIT 10")
    List<Map> getQuantityByWeek(@Param("year") int year);

    @Select("select SUM(food_quantity) quantity, DATE_FORMAT(create_time,'%Y-%m') months from order_detail GROUP BY months HAVING months LIKE CONCAT(#{year}, '%') order by months DESC")
    List<Map> getQuantityByMonth(@Param("year") int year);

    @Select("select SUM(food_quantity) quantity, CONCAT(YEAR(create_time), '-', QUARTER(create_time)) seasons from order_detail GROUP BY seasons HAVING seasons LIKE CONCAT(#{year}, '%')  ORDER BY seasons DESC")
    List<Map> getQuantityBySeason(@Param("year") int year);
}
